module StringSet = Set.Make(String);;


class dictionary (dict_file : in_channel) =
    object (self)
        val mutable words = StringSet.empty;

        initializer
            try
                while true do
                    words <- (StringSet.add
                                (String.lowercase
                                    (input_line dict_file))
                                words)
                done
            with _ -> close_in dict_file;

        method check word =
            StringSet.exists (( = ) (String.lowercase word)) words
    end
;;


(* Need to be recursive for let binding of neg_check to use 'dict'. *)
let dict = new dictionary(open_in Sys.argv.(1)) in
let check_words = Str.split (Str.regexp "[ \t]+") Sys.argv.(2) in
let neg_check = function x -> not (dict#check x) in
List.iter print_endline (List.filter neg_check check_words)
